﻿@model WebshopHPWcore.Models.ShoppingCartViewModels.ShoppingCartViewModel
@inject Microsoft.AspNetCore.Antiforgery.IAntiforgery Xsrf
@{
    ViewBag.Title = "Winkelwagen";
}
@functions
{
    public string GetAntiXsrfRequestToken()
    {
        return Xsrf.GetAndStoreTokens(Context).RequestToken;
    }
}

@section Scripts {
    <script type="text/javascript">
        $(function () {
            // Document.ready -> link up remove event handler
            $(".RemoveLink").click(function () {
                // Get the id from the link
                var recordToDelete = $(this).attr("data-id");
                var PostToUrl = $(this).attr("data-url");
                if (recordToDelete != '') {

                    // Perform the ajax post
                    $.ajax(PostToUrl, {
                        type: "post",
                        data: {
                            "id": recordToDelete
                        },
                        dataType: "json",
                        headers: {
                            "RequestVerificationToken": '@GetAntiXsrfRequestToken()'
                        }
                    }).done(function (data) {
                        // Successful requests get here
                        // Update the page elements
                        if (data.itemCount == 0) {
                            $('#row-' + data.deleteId).fadeOut('slow');
                        } else {
                            $('#item-count-' + data.deleteId).text(data.itemCount);
                        }

                        $('#cart-total').text(data.cartTotal);
                        $('#update-message').text(data.message);
                        $('#cart-status').text(data.cartCount);
                    });
                }
            });
        });
    </script>
}

<br />
<h2>Overzicht van uw winkelwagen</h2>
<br />
<div id="update-message">
</div>
<table id="cart-summary" class="table table-bordered table-responsive table-hover table-striped">
    <tr></tr>
    @foreach (var item in Model.CartItems)
    {
        <tr id="row-@item.CartItemId">
            <td width="300">
                @if (item.Car.color == "Wit")
                { <img src="~/images/auto1.jpg" alt="Visual Studio" class="img-responsive" /> }
                @if (item.Car.color == "Zilver")
                { <img src="~/images/auto2.jpg" alt="Visual Studio" class="img-responsive" />   }
                @if (item.Car.color == "Grijs")
                {  <img src="~/images/auto3.jpg" alt="Visual Studio" class="img-responsive" />     }
                @if (item.Car.color == "Rood")
                { <img src="~/images/auto4.jpg" alt="Visual Studio" class="img-responsive" /> }
                @if (item.Car.color == "Blauw")
                { <img src="~/images/auto5.jpg" alt="Visual Studio" class="img-responsive" />   }
                @if (item.Car.color == "Zwart")
                {  <img src="~/images/auto6.jpg" alt="Visual Studio" class="img-responsive" />     }
                @if (item.Car.color == "Geel")
                { <img src="~/images/auto7.jpg" alt="Visual Studio" class="img-responsive" /> }
                @if (item.Car.color == "Oranje")
                { <img src="~/images/auto8.jpg" alt="Visual Studio" class="img-responsive" />   }
                @if (item.Car.color == "Groen")
                {  <img src="~/images/auto9.jpg" alt="Visual Studio" class="img-responsive" />     }
            </td>
            <td>
                <h4>@item.Car.brand @item.Car.model</h4>
                
                <h5>€  @item.Car.price ,-</h5>
            </td>
            <td id="item-count-@item.CartItemId">
                <h5>Aantal: @item.Count</h5>
            </td>
            <td>
                <a asp-controller="ShoppingCart" asp-action="Details" asp-route-id="@item.carid" class="btn btn-default" style="float:right">Details</a>
                
                <br />
                <br />
                <a asp-controller="WishList" asp-action="AddToCart" asp-route-id="@item.carid" class="btn btn-default" style="float:right;"><i class="fa fa-heart" style="font-size:20px;color:red;"></i></a>
                <br />
                <br />
                <a href="#" class="btn btn-default RemoveLink" style="float:right;background-color:#F04C33" data-id="@item.CartItemId" 
                   data-url='@Url.Content("~/ShoppingCart/RemoveFromCart")'><i class="fa fa-trash" aria-hidden="true" style="font-size:24px;"></i></a>
            </td>
        </tr>
    }
    <tr>
        <td>
            <b>Totaal</b>
        </td>
        <td id="cart-total">
            € @Model.CartTotal ,-
        </td>
        <td></td>
        <td></td>
    </tr>
</table>
<br />

<p >
    <a asp-controller="Car" asp-action="Carpage" class="koop-knopje-links"><< Verder winkelen</a>
</p>

<p >
    <a asp-controller="ShoppingCart" asp-action="Review" class="koop-knopje">Verder naar bestellen >></a>
</p>
<br />
<br />
